﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum ActionSub
{
    BaseData  =0,
    Interrupt =1,
    AttackDef =2,
    Event     =3,
}
public class ActionSubDataPanel : MonoBehaviour
{
    public Transform viewRoot,cacheRoot;
    public RootItem[] rootItem;
    public SubRootItem subRootItem;

    private Data.Action actionData;
    private UIObjCacheProcess<SubRootItem> itemPool;
    public UIObjCacheProcess<SubRootItem> GetPool()
    {
        return itemPool;
    }
    private void OnEnable()
    {
        if (itemPool == null)
        {
            itemPool = new UIObjCacheProcess<SubRootItem>(cacheRoot, viewRoot, subRootItem);
        }
        EventManager.AddEventListener<Data.Action, ActionListItem>(CommonEvent.SelectOneActionDataToSubPanel, OnSelectOneActionData);
    }
    private void OnDisable()
    {
        EventManager.RemoveEventListener<Data.Action, ActionListItem>(CommonEvent.SelectOneActionDataToSubPanel, OnSelectOneActionData);
    }

    private void OnSelectOneActionData(Data.Action action, ActionListItem item)
    {
        OpenActionSubPanel(action);
    }

    public void OpenActionSubPanel(Data.Action data)
    {
        gameObject.SetActive(true);
        actionData = data;
        for (int i = 0; i < rootItem.Length; i++)
        {
            rootItem[i].SetData(data,this);
        }
    }
}